﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class HoaDonMonAnDAO
    {
        public static bool Insert(HoaDonKhachHangDTO hd)
        {
            bool result = false;

            string strSQLEmployee = "Insert into HoaDonKhachHang(KhachHang,NgayLap,TriGia) " +
                "values (@KhachHang,@NgayLap,@TriGia)";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@KhachHang", hd.MaKH));
                sqlParams.Add(new SqlParameter("@NgayLap", hd.NgayLap));
                sqlParams.Add(new SqlParameter("@TriGia", hd.TriGia));
                // Call execute none query

                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);//.ExecuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static int Search_ID(int makh, string nglap, string trgia)
        {
            //String strSql = "select MaHD from HoaDonKhachHang where KhachHang = " + makh + " and NgayLap = '" + nglap + "' and TriGia = " + trgia + "";
            String strSql = "select max(MaHD) as MaHD from HoaDonKhachHang ";
            try
            {
                DataTable dt = SqlDataAccessHelper.ExcuteQuery(strSql);
                DataRow dr = dt.Rows[0];
                return int.Parse(dr["MaHD"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
